<template>
    <div>
        <setHeader title="新闻管理"></setHeader>
        <div class="content">
            <div class="main-news_manage">
                <!-- <div class="emptyProduct" v-if="infolist == ''" style="margin-top:0.6rem;">
                    <img src="../common/images/empty.png" alt="">
                    <p>暂无数据  ╮(￣▽￣)╭</p>
                </div> -->
                <div v-if="infolist == ''" class="contentEmpty" style="margin-top: .2rem;margin-bottom: 0.8rem;">
                    <img src="../common/images/Disappointment.png" alt="">
                    <em>暂无查询结果</em>
                </div>
                <!-- 新闻列表-单图--多图 -->
                <div class="info_list" v-for="(initem, t) in infolist" :key="t" v-else>
                    <ul>
                        <li class="clear" @click="newseditorClick(initem.IDNews)" v-if="initem.count ==1">
                            <div class="info_list_item_left">
                                <img :src="initem.img" alt="" v-if="initem.img">
                                <img src="../common/images/cindex_41.jpg" v-else >
                            </div>
                            <!-- <p>{{initem.info_name}}</p> -->
                            <p>{{initem.Title}}</p>
                            <p class="info_time"><span>{{initem.summary}}</span><span>{{initem.dtCreate | dateFormat("yyyy-MM-dd hh:mm")}}</span></p>

                        </li>
                        <li  @click="newseditorClick(initem.IDNews)" v-else>
                            <div class="info">
                                <p>{{initem.Title}}</p>
                                <ul>
                                    <li v-for="(info, fo) in initem.img" :key="fo">
                                        <img :src="info" alt="" v-if="info">
                                        <img src="../common/images/cindex_28.jpg"  v-else>
                                    </li>
                                </ul>
                                <p class="info_time"><span>{{initem.summary}}</span><span>{{dtCreate | dateFormat("yyyy-MM-dd hh:mm")}}</span></p>
                                <!-- <span>无忧健身器材</span>  -->
                                </div>
                        </li>
                    </ul>
                </div>
                <!-- 添加 -->
                <div class="main_tianjia" @click="newsInsert"  v-if="t_show">
                    <i class="iconfont icon-jia"></i>
                </div>
            </div>
        </div>
        <so-footer></so-footer>
    </div>
</template>

<script>
import setHeader from '../public/setHeader.vue';
import soFooter from '../components/footer-bar';
    export default {
        data() {
            return {
                c_id: '',
                Title: '',
                dtCreate: '',
                IDNews: '',
                infolist: [],
                infos: [
                    {id:1},{id:2},{id:3}
                ],
                cpId: '',
                t_show:true,
                userInfo:'',
                /*infolist: [
                    {
                        info_name: '从零开始学习健身，第15天，参照第一天的样子，照第一天的样子。',
                        into_company: '北京朝阳区块链有限公司',
                        info_time: '2018-11-21'
                    }
                ],*/
            }
        },
        mounted() {
            this.cpId = this.$route.query.cp_id;
           
            this.u_type = this.$route.query.u_type;
            this.userInfo = JSON.parse(window.localStorage.getItem('userInfo'));
            if(this.u_type == 1){
                this.t_show = true;
            }else{
                this.t_show = false;
            }
             this.newslist();
        },
        methods: {
            newslist() {
                let c_id = this.$route.query.cp_id;
                let userId = this.userInfo.uid;
                this.$fetch(this.$path + '/index.php/api/NewsList', {c_id,userId}).then((response) => {
                    console.log('新闻列表',response);
                    if(response.code == 200) {
                        this.infolist = response.data;
                        response.data.forEach(item => {
                            this.Title = item.Title;
                            this.dtCreate = item.dtCreate;
                        });
                    }
                })
            },
            newseditorClick(id) {
                if(this.u_type ==1){
                    this.$router.push({
                        path: '/userCenter/newsEditor',
                        query: {id: id}
                    })
                }else{
                    this.$router.push({
                        path: '/newsDetail',
                        query: {id: id}
                    })
                }
            },
            newsInsert() {
                if(this.cpId == undefined){
                    this.$router.push({
                        path: '/userCenter/newsInsert',
                        query: {cpId: 0}
                    })
                }else{
                    this.$router.push({
                        path: '/userCenter/newsInsert',
                        query: {cpId: this.cpId}
                    })
                }
                
            },
            // goback(cpId) {
            //     this.$router.push({
            //         path: '/userCenter/companyData',
            //         query: {cpId: this.cpId,u_type:this.u_type}
            //     })
            // },
            // goback() {
            //     window.history.back();
            // },
        },
        components: {
            setHeader,
            soFooter
        }
    }
</script>

<style>
/* 添加 */
.main-insert {
    margin-top: 0.62rem;
}
.main-insert .add_active_manage {
    width: 1rem;
    height: 1rem;
    background-color: #e50838 !important;
    border-radius: 50%;
    margin-bottom: 0.4rem;
    margin: 0.7rem;
}
.main-insert .add_active_manage .icon-jia {
    font-size: 0.48rem;
    line-height: 1rem;
    vertical-align: text-top;
    text-align: center;
    color: #fff;
}

/* 新闻列表--多图 */

.info {
    padding: 0 !important;
    border-bottom: 1px solid #f2f2f2;
}

.info_list .info p {
    font-size: .28rem;
    color: #333;
    text-align: left;
    margin-bottom: 0.2rem;
    padding-bottom: 0;
    background-color: transparent;
}

.info_list .info ul {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 0.12rem;
    margin-left: 0;
}

.info_list .info ul>li {
    margin-right: 0.16rem;
    border: none;
    padding: inherit;
    position: unset;
}

.info_list .info ul>li:last-child {
    margin-right: 0;
}

.info_list .info ul>li img {
    width: 2.26rem;
    height: 1.46rem;
    display: block;
}

.info_list .info .info_time {
    display: flex;
    justify-content: space-between;
    font-size: .22rem;
    color: #999;
    color: #999;
    position: unset;
    width: auto;
}
.info_list ul>li p span:first-child {
    width: 2rem;
    white-space: nowrap;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
    overflow: hidden;
    display: inline-block;
}


/* 新闻列表--单图 */

.info_list {
    padding: 0 .2rem;
}

.info_list ul {
    margin: 0 -.2rem;
}

.info_list ul>li {
    border-bottom: 1px solid #f2f2f2;
    padding: 0.3rem 0.2rem;
    position: relative;
}

.info_list :last-child {
    border-bottom: none;
}

.info_list ul>li .info_list_item_left {
    float: left;
    margin-right: 0.3rem;
    width: 1.2rem;
    height: 1.2rem;
    text-align: center;
    vertical-align: middle;
    display: block;
}

.info_list ul>li .info_list_item_left img {
    width: 1.2rem;
    height: 1.2rem;
    max-width: 100%;
    max-height: 100%;
}

.info_list ul>li p {
    font-size: .28rem;
    color: #333;
    text-align: left;
    padding-bottom: 0;
    background-color: transparent;
}
.info_list .info ul>li{
    padding: 0;
}

.info_list ul>li p:last-child {
    font-size: .22rem;
    color: #999;
    display: flex;
    justify-content: space-between;
    position: absolute;
    width: 76%;
    bottom: 0.2rem;
    right: 0.2rem;
    line-height: 0.3rem;
}

/* 添加 */
.main_tianjia {
    width: 1rem;
    height: 1rem;
    background-color: #e50838 !important;
    border-radius: 50%;
    margin-bottom: 0.4rem;
    margin: 0 auto;
    margin-top: 0.4rem;
}
.main_tianjia .icon-jia {
    font-size: 0.48rem;
    line-height: 1rem;
    vertical-align: text-top;
    text-align: center;
    color: #fff;
}


/* 新闻为空 */
.main-news_manage .emptyProduct {
  padding: 0 0 0.2rem;
  box-sizing: border-box;
}
.main-news_manage .emptyProduct img {
  width: 1.56rem;
  height: 1.22rem;
  margin: 0 auto;
}
.main-news_manage .emptyProduct p {
  font-size: 0.26rem;
  color: #999;
  text-align: center;
}


</style>